<template>
	<view>
		<van-tabs active="a">
			<van-tab title="签到任务" name="a">
				<view class="" v-for="(item,index) in signList">
					<view class="" style=" width: 95%; margin: auto;margin-top: 40rpx;">
						<view class="cellview">
							<van-cell-group>
								<van-cell :title="item.signEnt.title" is-link @click="signDetail()"
									:value="item.statusEnum" size="large"
									icon="cloud://cu4oral6-9g3l2orjbb347b4c.6375-cu4oral6-9g3l2orjbb347b4c-1307874055/群组.png" />
							</van-cell-group>
						</view>
					</view>
				</view>

				<view class="" style=" width: 95%; margin: auto;margin-top: 40rpx;">
					<view class="cellview">
						<van-cell-group>
							<van-button @click="addSign" plain hairline type="info" block>新建签到</van-button>
						</van-cell-group>
					</view>
				</view>
			</van-tab>
			<van-tab title="系统通知" name="c">
				<view class="" style=" width: 95%; margin: auto;margin-top: 40rpx;">
					<view class="cellview">
						<van-cell-group v-for="(item,index) in requestList.list">
							<van-cell :title="item.leaveName" :value="item.approveResult" size="large"
							is-link @click="signDetail()" :data-index="index" :data-id="item.requesterId"
								icon="cloud://cu4oral6-9g3l2orjbb347b4c.6375-cu4oral6-9g3l2orjbb347b4c-1307874055/群组.png" />
						</van-cell-group>
					</view>
				</view>
			</van-tab>
		</van-tabs>
		<!-- 弹出框 -->
		<van-dialog id="van-dialog" />

	</view>
</template>

<script>
	import Dialog from '../../wxcomponents/vant/dialog/dialog';
	export default {
		data() {
			return {
				signList: [{
					"id": 1,
					"executor": 3,
					"signId": 1,
					"signEnt": {
						"id": 1,
						"title": "第一次签到",
						"issuer": null,
						"startTime": "2021-11-26 14:14:20",
						"aimGroup": null,
						"groupEnt": null,
						"labelId": null,
						"labelEnt": null,
						"limitTime": "2021-11-28 14:14:20",
						"aimUserIdList": null
					},
					"statusEnum": "WAITING"
				}],
				requestList: {
					"status": 1,
					"message": null,
					"data": null,
					"list": [{
						"id": 1,
						"requesterId": 3,
						"aimGroup": 1,
						"requestTime": "2021-11-01 23:33:11",
						"message": "拒绝考研，从我做起。",
						"leaveName": "17土木二班卢斌",
						"reviewer": 0,
						"judgeTime": null,
						"approveResult": "WAITING"
					}],
					"pageNum": 1,
					"pageSize": 3,
					"totalPage": 1,
					"lastPage": true,
					"firstPage": true
				}
			}
		},
		methods: {
			//签到信息
			signDetail() {
				Dialog.alert({
					message: '签到任务',
				}).then(() => {
					// on close
				});
			},
			//申请信息
			signDetail(e) {
				Dialog.alert({
					message: `申请信息：${this.requestList.list[e.target.dataset.index].message}\n
					申请时间：${this.requestList.list[e.target.dataset.index].requestTime}\n
					审批时间：${this.requestList.list[e.target.dataset.index].judgeTime}\n
					`,
					showCancelButton:"true",
					confirmButtonText:"同意",
					cancelButtonText:"拒绝",
					closeOnClickOverlay:"true"
				}).then(() => {
					uni.request({
						url: this.apiurl + '/user_join/judge_request', 
						header: {
							'Authorization': uni.getStorageSync('token') //自定义请求头信息
						},
						data: {
							requestId: e.target.dataset.id,
							result: "PERMISSION"
						},
						success: (res) => {
							console.log(res.data)
						}
					});
				}).catch(() => {
					uni.request({
						url: this.apiurl + '/user_join/judge_request', 
						header: {
							'Authorization': uni.getStorageSync('token') //自定义请求头信息
						},
						data: {
							requestId: e.target.dataset.id,
							result: "REJECTION"
						},
						success: (res) => {
							console.log(res.data)
						}
					});
				});
			},
			//增加签到
			addSign() {
				uni.navigateTo({
					url: '/pages/addSign/addSign'
				});
			},
			//socket连接
			noticeScoket() {
				uni.connectSocket({
					url: 'wss://www.mrslu.top/websocket?userCode=',
					data() {
						return {
							x: '',
							y: ''
						};
					},
					header: {
						'content-type': 'application/json'
					},
					protocols: ['protocol1'],
					method: 'GET'
				});
			},
			//查询签到任务
			findSign() {
				uni.request({
					url: this.apiurl + '/sign/user_task', //仅为示例，并非真实接口地址。
					header: {
						'Authorization': uni.getStorageSync('token') //自定义请求头信息
					},
					data: {
						pageNum: 1,
						pageSize: 20
					},
					success: (res) => {
						console.log(res.data)
						this.signList = res.data.list
					}
				});
			},
			//查询和用户相关的加群申请
			findRequest() {
				uni.request({
					url: this.apiurl + '/user_join/user_request', //仅为示例，并非真实接口地址。
					header: {
						'Authorization': uni.getStorageSync('token') //自定义请求头信息
					},
					data: {
						pageNum: 1,
						pageSize: 20
					},
					success: (res) => {
						console.log(res.data)
						this.requestList = res.data
					}
				});
			}
			//
		},
		onShow() {
			//检查登录状态
			this.checkLogin();
			//更新token
			// this.aginLogin();
			//查询签到任务
			this.findSign();
			this.findRequest();
		}
	}
</script>

<style>
	page {
		background-image: url("../../static/bg.webp");
		background-position: center;
		background-size: cover;
	}

	.van-cell {
		border-radius: 10rpx;
	}
</style>
